perm filename PROB5.PUB[LSP,JRA]3 blob sn#091302 filedate 1974-03-11 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.SS(Problems)
C00005 ENDMK
C⊗;
.SS(Problems)
.BEGIN CENTERIT;TABIT2(10,23);SELECT 1;
.GROUP
I  Use the following defintion:
%3
\match[k;m] <=\[null[k] → NO;
\\ null[m] → NO;
\\ eq[car[k];car[m]] → car[k];
\\ T → match[cdr[k];cdr[m]]]

%1
and evaluate:
%21.%3 match[(X);(X)]   %22.%3 match[(A B E);(J O E)]  %23.%3 match[(F O O); (BAZ)]
.APART
%1
.GROUP

II  Now write your own.
.BEGIN FILL;INDENT 0,7;

%21.%3 among[x;y] <= ... : among%1 is to be a predicate; %3x%1 is an atom; %3y%1 is a list
of atoms.  %3among%1 is to return %3NIL%1 if %3x%1 is not found as an element of %3y%1; o.w.
among is to return %3T%1.
.END

\e.g. %3among[A;(A B C)] = among[A;(C D E A)] = T
\     among[A1;(A2 B2)] = NIL.
%1

.BEGIN FILL;INDENT 0,7;
%22.%3 anywhere[x;y] <= ... : anywhere%1 is a predicate; %3x%1 is an atom; %3y%1 is an arbitrary
sexpr. %3anywhere%1 is to return %3T%1 just in the case that %3x%1 appears somewhere in %3y%1.
.END

\e.g. %3anywhere[A;(A B C)] = anywhere[A;((A . B). C)] = T
\     anywhere[A;(B C D)] = NIL.
%1

.BEGIN INDENT 0,7;FILL;
%23.%3 collectpair[z;x;y] <= ... : %3x%1 and %3y%* are atoms; %3z%* is an sexpression,
some of whose subexpressions, may begin %3(x ...)%* or %3(y ...)%*.  %3collectpair%*
is to return a dotted pair whose %3car%*-part is a list of all the occurrences
of %3(x...)%*  and whose %3cdr%*-part is a list of all occurrences of %3(y ...)%*.
.END

\e.g. %3collectpair[((A 1)((B . 2)(C A 4)));A;B] = (((A 1)(A 4)).((B . 2)))
.FILL
%1
.END